<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysqli.inc.php';
include_once '../inc/tool.inc.php';
$link=connect();
if(isset($_POST['submit'])){
   // var_dump($_POST);exit();
   foreach($_POST['sort'] as $key=>$val){
        if(!is_numeric($val)||!is_numeric($key)){
            skip('fatherModule.php','error','输入参数不合法！ ');
        }    
        $query[]="update fatherModule set sort=$val where id=$key";
    } 
        $result=execute_multi($link,$query,$error);
        if($result){
            skip('fatherModule.php','ok','修改成功！ ');
        }else{
            skip('fatherModule.php','error',$error);
   }
}
?>
<?php
$template='父板块列表';
include_once 'inc/header.inc.php';
?>
    <div id="main">
    <div class="intro"><?php echo $template ?></div>
    <form method="post">
        <table class="cont">
            <tr>
                <th>排序</th>
                <th>板块名称</th>
                <th>操作</th>
            </tr>
    <?php
        $query="select *from fatherModule";
        $result=execute($link,$query);
        while($data=mysqli_fetch_assoc($result)){
            $data=dehtml($data);
            $url=urlencode("fm_delete.php?id={$data['id']}");
            $rturl=urlencode("$_SERVER[REQUEST_URI]");
            $message=urlencode("确认要删除父板块 <span style='color:rgb(218, 126, 114);'>{$data['moduleName']}</span> 的内容么？&nbsp;&nbsp;");
            $delurl="confirm.php?url={$url}&rturl={$rturl}&message={$message}";
            $upurl="fm_update.php?id={$data['id']}";
$html=<<< A
            <tr>
                <td><input class="sort" type="text" value="{$data['sort']}" name="sort[{$data['id']}]" /></td>
                <td>{$data['moduleName']}[id:{$data['id']}]</td>
                <td><a href="#">[访问]</a>&nbsp;&nbsp;<a href="$upurl">[编辑]</a>&nbsp;&nbsp;<a href="$delurl">[删除]</a></td>
            </tr>
A;
                echo $html;
            }
        ?>           
        </table>
        <div class="division"></div>
        <input type="submit" name="submit" value="排序" class="nsubmit" />
    </form>
   
    </div>

<?php
    include_once 'inc/footer.inc.php';
?>